<template>
    <m-navbar :isNeedBack="false" title="成绩"/>
    <m-tabbar :activeId="3"/>
    <!-- 无数据 -->
    <template v-if="!examinationList.length">
        <view class="w-full h-page-empty flex-justifyCenter-itemsCenter-box">
            <u-empty
                mode="order"
                width="200"
                text="暂无考试哦~"
                icon="https://cdn.uviewui.com/uview/empty/order.png"
            />
        </view>
    </template>
    <!-- 成绩列表 -->
    <template v-else>
        <view class="content-wrap flex-wrap tab-page-height">
            <template v-if="authType === 1">
                <view
                    class="w-full text-white px-16 box-border examination rounded-8 common-shadow bg-primary flex-justifyBetween-itemsCenter-box mb-10"
                    v-for="item in examinationList"
                    :key="item.id"
                    @click="toPage(item)"
                >
                    <text>{{ item.examName }}（{{ item.courseName }}）</text>
                    <text>查看</text>
                </view>
            </template>
            <template v-else>
                <view
                    class="class-box mr-10 mb-10"
                    v-for="item in classList"
                    :key="item.id"
                >
                    <u-button
                        color="#70B9BE"
                        type="primary"
                    >
                        {{ item.name }}
                    </u-button>
                </view>
            </template>
        </view>
    </template>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { PageParams } from '@/api/request'
import { getMarkList } from '@/api/modules/achievement'

const authType = ref(1)
// 分页数据
const pageParams: PageParams = reactive({
	pageNum: 1,
	pageSize: 10,
	status: '0'
})

const examinationList = ref([])

// 总数据
const total = ref(0)
const toPage = (row) => {
    uni.setStorageSync('markInfo', row)
	uni.navigateTo({
		url: '/pages/achievementDetail/index'
	})
}

const getAchievementList = () => {
    const { classId } = uni.getStorageSync('userInfo')
    getMarkList({
        pageNum: 1,
        pageSize: 100,
        classNumber: classId
    }).then(res => {
        console.log('res', res)
        if (res.code === 200 && res.rows.length) {
            examinationList.value = res.rows
        } else {
            examinationList.value = []
        }
    })
}

onShow(() => {
	getAchievementList()
})
</script>

<style scoped lang="scss">
.class-box {
    width: calc(50% - 10rpx);
}

.content-wrap {
    & :nth-child(2n) {
        margin-right: 0;
    }
}

.examination {
    height: 80rpx;
}
</style>
